package com.hns.phone.pushMsg.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hns.phone.pushMsg.vo.PushMessageParamsVo;
import com.hns.tool.pub.DateTool;
import com.hns.tool.pub.PubUtil;

@Component
public class IOSListNotification extends IOSNotification {

	@Autowired
	private BasePushClient client;
	
	
	/**
	 * 发送信息动作
	 * @param params
	 * @throws Exception
	 * @see com.hns.can.pushMsg.util.AndroidNotification#sendMsg(com.hns.can.pushMsg.vo.PushMessageParamsVo)
	 * @author:zhangyu
	 * @email:zhangyu2222z@sina.cn
	 */
	@Override
	public String sendMsg(PushMessageParamsVo params) throws Exception {
		this.setPredefinedKeyValue("type", "listcast");
		//组装发送设备tokens，多个device_token用英文逗号分隔
		this.setPredefinedKeyValue("device_tokens", params.getTokenStr());
		setAppMasterSecret(params.getAppMasterSecret());
		setPredefinedKeyValue("appkey", params.getAppkey());
		this.setPredefinedKeyValue("type", "listcast");
		this.setAlert(params.getContent());
		this.setCustomizedField("title", params.getTitle());
		
//		this.setCustomizedField("msg_id", params.getMsgId());
		
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		this.setCustomizedField("creat_time", format.format(new Date()));
//		if(PubUtil.isNotEmpty(params.getWebUrl())){
//			this.setCustomizedField("url", params.getWebUrl());
//		}else{
//			removeCustomizedField("url");
//		}
		
		if(AndroidNotification.DisplayType.MESSAGE.getValue().equals(params.getDisplayType())){
			this.setCustomizedField("type", "message");
		}else{
			this.setCustomizedField("type", "notification");
		}
		
		this.setCustomizedField("userId", params.getUserId());
		this.setCustomizedField("msgDate", params.getMsgDate());
		
		this.setBadge(0);
		this.setSound("default");
		this.setProductionMode();
		if(PubUtil.isNotEmpty(params.getDelayTime())){
			this.setStartTime(params.getDelayTime() + "00:00:00");
			String expireTime = DateTool.calculateByDate(params.getDelayTime(), 3);
			this.setExpireTime(expireTime + "23:59:59");
		}
		String taskId = client.sendMsg(this);
		return taskId;
	}
	
}
